package com.pyg.manager.controller;

import com.alibaba.dubbo.config.annotation.Reference;

import com.pyg.pojo.TbContent;
import com.pyg.goods.service.TbContentService;

import entity.PageResult;
import entity.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
*  @Author zhuliangcai
*  @Email zhuliangcai@itcast.cn
*  @Date 2018-04-03 20:07:45

*/
@RestController
@RequestMapping("/tbContent")
public class TbContentController {
    @Reference
    private TbContentService tbContentService;
    @RequestMapping("/findAll")
    public List<TbContent> findAll() {
        return tbContentService.findAll();
    }
    @RequestMapping("/findPage")
    public PageResult findPage(int pageNum, int pageSize) {
        return tbContentService.findPage(pageNum,pageSize);
    }
    @RequestMapping("/search")
    public PageResult search(@RequestBody TbContent tbContent, int pageNum, int pageSize) {
        return tbContentService.findPage(tbContent,pageNum,pageSize);
    }
    @RequestMapping("/add")
    public Result add(@RequestBody TbContent tbContent) {

        try {
            tbContentService.add(tbContent);
            return new Result(true,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"添加失败");
        }
    }
    @RequestMapping("/del")
    public Result del(Long[] ids) {
        try {
            tbContentService.del(ids);
            return new Result(true,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"删除失败");
        }
    }
    @RequestMapping("/findOne")
    public TbContent findOne(Long id) {
        return tbContentService.findOne(id);
    }
    @RequestMapping("/update")
    public Result update(@RequestBody TbContent tbContent) {

        try {
            tbContentService.update(tbContent);
            return new Result(true,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"修改失败");
        }
    }
}
